package z_app_lotto2;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

class TotListFrame extends JInternalFrame {
	String fileName = null;
	Vector lotto;
	JTable table;
	JScrollPane scroll;
	MyTable model;

	String header[];
	int data[][];

	public TotListFrame(Vector v) {
		super("Total List",true, true, true, false);
		fileName = this.getClass().getSimpleName() + ".cfg";
	
		addInternalFrameListener(new InternalFrameAdapter() {
			@Override
			public void internalFrameOpened(InternalFrameEvent e) {
				setBounds(new InterWindowAdapter(fileName).read());
			}
			@Override
			public void internalFrameClosing(InternalFrameEvent e) {
				InterWindowAdapter adapter = new InterWindowAdapter(fileName);
				int x = getX();
				int y = getY();
				int w = getWidth();
				int h = getHeight();
				Rectangle rect = new Rectangle(x,y, w, h);
				adapter.save(rect);
			}
	
		});
		getContentPane().setLayout(new BorderLayout());
		
		this.setVisible(true);
		
		lotto = v;
		initHeader();
		initData();

		init();
	}

	public void initHeader() {
		header = new String[8];

		header[0] = "횟수";
		header[1] = "I";
		header[2] = "II";
		header[3] = "III";
		header[4] = "IV";
		header[5] = "V";
		header[6] = "VI";
		header[7] = "Bonus";

	}

	public void initData() {
		data = new int[lotto.size()][8];

		Vector v;
		for (int i = 0; i < lotto.size(); i++) {
			v = (Vector) lotto.get(i);
			for (int j = 0; j < 8; j++) {
				data[i][j] = Integer.parseInt((String) v.get(j));
			}
		}

	}

	public void init() {
		table = new JTable();
		model = new MyTable(header, data);
		scroll = new JScrollPane(table);
		table.setModel(model);

		getContentPane().add(scroll);
		this.updateUI();

	}


}
